package com.demo.tests.cases;

import com.demo.config.ApiEndpoints;
import com.demo.utils.LogUtils;
import io.qameta.allure.Allure;
import io.restassured.RestAssured;
import io.restassured.path.json.JsonPath;
import io.restassured.response.Response;
import org.apache.logging.log4j.Logger;
import org.testng.annotations.Test;
import org.testng.asserts.SoftAssert;

public class Basea3 {

    private static final Logger log = LogUtils.getLogger();

    @Test(groups = "a3")
    public void testLogin() {
        SoftAssert softAssert = new SoftAssert();

        // 1. 构造请求参数
        String requestBody = "{\"id\":1000111,\"sku_id\":\"\",\"num\":1}";

        // 2. 发送请求（添加必要的请求头）
        Response response = RestAssured.given()
                .header("Content-Type", "application/json")
                .header("Origin", "http://10.59.9.14:7003")
                .header("auth-token", "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIiLCJhdWQiOltdLCJqdGkiOiJXRUFEMm92Uk50IiwiaWF0IjoxNzU0MDM3NjgxLCJuYmYiOjE3NTQwMzc2ODAsImV4cCI6MTc1NTMzMzY4MSwiaWQiOiJNVFk1TVh3eE56VTBNRE0zTmpneGZETTJNRGN3TURFek56bG1PRGszTURNNFlXTXpNalF4WW1ZeU1tTXhOR1JtIn0.YqRfwmViZ6Vgz2u9Ub-Bp105qhC0nK6lA1saOljApgk")
                .body(requestBody)
                .post(ApiEndpoints.getFullUrl(ApiEndpoints.RONCOO_ADDSER));

        // 3. 验证响应
        softAssert.assertEquals(response.statusCode(),
                200,
                String.format("HTTP状态码不匹配，实际: %d", response.statusCode())
        );

        // 打印并记录响应信息
        String responseBody = response.asPrettyString();
        Allure.addAttachment("响应体", responseBody);
        log.info("API响应:\n{}", responseBody);

    }   
}